﻿Imports Hinshelwood.TFSStickyBuddy.Modules.Interfaces
Imports Microsoft.Practices.Composite.Regions
Imports Microsoft.Practices.Composite.Events
Imports Microsoft.Practices.Unity
Imports Microsoft.Practices.Composite.Wpf.Commands
Imports Hinshelwood.TFSStickyBuddy.Infrastructure
Imports Hinshelwood.TFSStickyBuddy.Infrastructure.Events
Imports Microsoft.TeamFoundation.WorkItemTracking.Client

Namespace Controllers


    Public Class KanbanController
        Implements IKanbanController

        Private ReadOnly m_regionManager As IRegionManager
        Private ReadOnly m_eventAggregator As IEventAggregator
        Private ReadOnly m_container As IUnityContainer
        Private Shared m_ByStatusCommand As DelegateCommand(Of Uri)
        Private Shared m_ByCustomCommand As DelegateCommand(Of Uri)

        Private m_SelectedProject As Project

        Public ReadOnly Property ByStatusCommand() As Microsoft.Practices.Composite.Wpf.Commands.DelegateCommand(Of System.Uri) Implements Interfaces.IKanbanController.ByStatusCommand
            Get
                Return m_ByStatusCommand
            End Get
        End Property

        Public ReadOnly Property ByCustomCommand() As Microsoft.Practices.Composite.Wpf.Commands.DelegateCommand(Of System.Uri) Implements Interfaces.IKanbanController.ByCustomCommand
            Get
                Return m_ByCustomCommand
            End Get
        End Property

        Public Sub New(ByVal regionManager As IRegionManager, ByVal container As IUnityContainer, ByVal eventAggregator As IEventAggregator)
            m_regionManager = regionManager
            m_eventAggregator = eventAggregator
            m_container = container
            m_ByStatusCommand = New DelegateCommand(Of Uri)(AddressOf OnByStatusExecuted, AddressOf OnByStatusCanExecute)
            m_ByCustomCommand = New DelegateCommand(Of Uri)(AddressOf OnByCustomExecuted, AddressOf OnByCustomCanExecute)
            ' Subscribe to Events
            m_eventAggregator.GetEvent(Of TeamProjectSelectionEvent).Subscribe(AddressOf OnTeamProjectSelection)

        End Sub

        Sub OnTeamProjectSelection(ByVal project As Project)
            m_SelectedProject = project
            ByStatusCommand.RaiseCanExecuteChanged()
            ByCustomCommand.RaiseCanExecuteChanged()
        End Sub


        Sub OnByStatusExecuted(ByVal server As Uri)
            '----------------------------
            m_eventAggregator.GetEvent(Of Events.NotImplementedEvent)().Publish(New Events.NotImplementedPayload("Kanban By Status", Me.GetType, "n/a"))

        End Sub

        Function OnByStatusCanExecute(ByVal server As Uri) As Boolean
            Return Not m_SelectedProject Is Nothing
        End Function

        Sub OnByCustomExecuted(ByVal server As Uri)
            '----------------------------
            m_eventAggregator.GetEvent(Of Events.NotImplementedEvent)().Publish(New Events.NotImplementedPayload("Custom Kanban", Me.GetType, "n/a"))

        End Sub

        Function OnByCustomCanExecute(ByVal server As Uri) As Boolean
            Return Not m_SelectedProject Is Nothing
        End Function

    End Class

End Namespace